<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>View Sale Lead | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        <p:panel id="panel" header="View Sale Leads">
            <h:form prependId="false">
            <p:dataTable id="table" var="saleLead" value="#{saleLeadDataTableBean.saleLeads}" 
                         dynamic="true" paginator="true" rows="5" emptyMessage="No sale lead found in database." 
                         selection="#{saleLeadDataTableBean.selectedSaleLead}"> 

                <p:column selectionMode="single" />

                <p:column sortBy="#{saleLead.saleLeadName}" filterBy="#{saleLead.saleLeadName}" style="width: 20%"> 
                    <f:facet name="header"> 
                        <h:outputText value="Company Name" /> 
                    </f:facet> 
                    <h:outputText value="#{saleLead.saleLeadName}" /> 
                </p:column> 

                <p:column sortBy="#{saleLead.registrationNumber}" filterBy="#{saleLead.registrationNumber}" style="width: 20%"> 
                    <f:facet name="header"> 
                        <h:outputText value="Registration Number" /> 
                    </f:facet> 
                    <h:outputText value="#{saleLead.registrationNumber}" /> 
                </p:column> 

               <p:column sortBy="#{saleLead.saleLeadAddress}" filterBy="#{saleLead.saleLeadAddress}" style="width: 40%"> 
                    <f:facet name="header"> 
                        <h:outputText value="Address" /> 
                    </f:facet> 
                    <h:outputText value="#{saleLead.saleLeadAddress}" /> 
                </p:column>

                <p:column sortBy="#{saleLead.customerType}" filterBy="#{saleLead.customerType}" style="width: 20%"> 
                    <f:facet name="header"> 
                        <h:outputText value="Customer Type" /> 
                    </f:facet> 
                    <h:outputText value="#{saleLead.customerType}" /> 
                </p:column>

                <f:facet name="footer">  
                    <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" onclick="saleLeadDialog.show()">

                    </p:commandButton>
                    <p:commandButton value="Edit" image="ui-icon ui-icon-pencil" actionListener="#{saleLeadDataTableBean.editSaleLead}"/>     
                    <p:commandButton value="Delete" image="ui-icon ui-icon-trash" update="display3 display4" onclick="saleLeadDeleteDialog.show()">
                        <f:setPropertyActionListener value="#{saleLead}" target="#{saleLeadDataTableBean.selectedSaleLead}"/>
                    </p:commandButton>
                    <p:growl id="messages" />
                    <p:menuButton value="Other Options">
                        <p:menuitem value="View Representatives" update="mesages" actionListener="#{saleLeadDataTableBean.viewRepresentatives}"/>
                        <p:menuitem value="Add New Sale Inquiry" update="messages" actionListener="#{saleLeadDataTableBean.addSaleInquiry}"/>
                        <p:menuitem value="Add New Sale Quotation" update ="messages" actionListener="#{saleLeadDataTableBean.addSaleQuotation}"/>
                        <p:menuitem value="View Sale Inquiries" update = "messages" actionListener="#{saleLeadDataTableBean.viewSaleInquiries}" />
                        <p:menuitem value="View Sale Quotation" update = "messages" actionListener="#{saleLeadDataTableBean.viewSaleQuotations}" />
                        </p:menuButton>

                </f:facet>
            </p:dataTable>
            <p:dialog header="Sale Lead Detail" widgetVar="saleLeadDialog" resizable="true" 
                          width="600" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2" cellpadding="4">
                        <h:outputText value="Sale Lead Name: " style="font-weight: bold"/>
                        <h:outputText value="#{saleLeadDataTableBean.selectedSaleLead.saleLeadName}"/>

                        <h:outputText value="Registration Number: " style="font-weight: bold"/>
                        <h:outputText value="#{saleLeadDataTableBean.selectedSaleLead.registrationNumber}"/>

                        <h:outputText value="Company Address: " style="font-weight: bold"/>
                        <h:outputText value="#{saleLeadDataTableBean.selectedSaleLead.saleLeadAddress}"/>

                        <h:outputText value="Customer Type: " style="font-weight: bold"/>
                        <h:outputText value="#{saleLeadDataTableBean.selectedSaleLead.customerType}"/>

                    </h:panelGrid>

                    <p:dataTable id="display2" var="rep" value="#{saleLeadDataTableBean.selectedSaleLead.representatives}"
                                 dynamic="true" paginator="true" emptyMessage="No Representative" >
                        <p:column sortBy="#{rep.name}" style="width: 30%">
                            <f:facet name="header">
                                <h:outputText value="Representative"/>
                            </f:facet>
                            <h:outputText value="#{rep.name}"/>
                        </p:column>

                        <p:column sortBy="#{rep.email}"  style="width: 40%">
                            <f:facet name="header">
                                <h:outputText value="Email"/>
                            </f:facet>
                            <h:outputText value="#{rep.email}"/>
                        </p:column>

                        <p:column sortBy="#{rep.contactNumber}"  style="width: 30%">
                            <f:facet name="header">
                                <h:outputText value="Contact Number"/>
                            </f:facet>
                            <h:outputText value="#{rep.contactNumber}"/>
                        </p:column> 


                    </p:dataTable>                            
                </p:dialog>
            </h:form>
        </p:panel>
    </ui:define>

</ui:composition>
